package com.kzd.sdk.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;

import com.kzd.sdk.callback.KZD_OnClickListener;
import com.kzd.sdk.callback.KZD_OnSmallListener;
import com.kzd.sdk.utils.AppUtils;

public class KZD_ServiceCodeDialog extends Dialog {


    public KZD_ServiceCodeDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(AppUtils.getLayoutId(getContext(), "kzd_dialog_service_code"));
        initView();
    }

    @Override
    protected void onStart() {
        super.onStart();
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        getWindow().setAttributes(params);
        getWindow().getDecorView()
                .setPadding((0), (0), (0), (0));
        getWindow().getDecorView()
                .setBackgroundColor(Color.TRANSPARENT);
        getWindow().setGravity(Gravity.CENTER);
    }

    private ImageView ivServiceQrCodeImage;

    private void initView() {
        ivServiceQrCodeImage = findViewById(AppUtils.getId(getContext(), "ivServiceQrCodeImage"));
        ivServiceQrCodeImage.setImageResource(mDrawableRes);
        findViewById(AppUtils.getId(getContext(), "tvServiceQrCodeCancel"))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        cancel();
                    }
                });
        findViewById(AppUtils.getId(getContext(), "tvServiceQrCodeDown"))
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (mOnClickListener != null) {
                            mOnClickListener.onClick(v);
                        }
                    }
                });
//        TextView tvServicePhoneConfirm = findViewById(AppUtils.getId(getContext(), "tvServicePhoneConfirm"));
//        tvServicePhoneConfirm.setText(new StringBuilder("tel：").append(mPhone));
//        tvServicePhoneConfirm.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                cancel();
//                if (TextUtils.isEmpty(mPhone)) {
//                    return;
//                }
//                Intent intent = new Intent(Intent.ACTION_DIAL);
//                Uri data = Uri.parse("tel:" + mPhone);
//                intent.setData(data);
//                mContext.startActivity(intent);
//            }
//        });
    }

    private @DrawableRes
    int mDrawableRes;

    public void setImage(@DrawableRes int src) {
        mDrawableRes = src;
    }

    private KZD_OnClickListener mOnClickListener;

    public void setOnClickListener(KZD_OnClickListener listener) {
        this.mOnClickListener = listener;
    }
}
